package com.wing.res.controller;

import com.wing.common.exception.BusinessException;
import com.wing.common.utils.JsonResult;
import com.wing.res.model.entity.ReceiptRecordDetail;
import com.wing.res.service.ReceiptRecordDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 领料记录明细-controller
 *
 * @author xiayang
 */
@Validated
@Api(value = "领料记录明细管理", tags = "#/receiptRecordDetail/receiptRecordDetail")
@RestController("receiptRecordDetailController")
@RequestMapping("receiptRecordDetail/admin/receiptRecordDetail")
@RequiredArgsConstructor
public class ReceiptRecordDetailController {

    private final ReceiptRecordDetailService receiptRecordDetailService;

//    @ApiOperation(value = "查询领料记录明细列表", notes = "搜索")
//    @GetMapping("/list")
//    public PageResult<ReceiptRecordDetail> list(
//            @RequestParam(defaultValue = "1") Integer page,
//            @RequestParam(defaultValue = "10") Integer limit) {
//        Page<ReceiptRecordDetail> pg = new Page<>(page, limit);
//        Map<String, Object> params = new HashMap<String, Object>();
//        IPage<ReceiptRecordDetail> list = receiptRecordDetailService.list(pg, params);
//        return new PageResult<>(list.getRecords(), list.getTotal());
//    }

    @ApiOperation(value = "添加领料记录明细", notes = "添加")
    @PostMapping("/save")
    public JsonResult save(@RequestBody List<ReceiptRecordDetail> receiptRecordDetails) {
        try {
            receiptRecordDetailService.saveBatch(receiptRecordDetails);
        } catch (BusinessException e) {
            return JsonResult.fail(e.getMessage());
        }
        return JsonResult.success("添加成功");
    }
}
